package com.wc.codeforces.思维.Product_of_Binary_Decimals;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/6/18 11:10
 * @description https://codeforces.com/problemset/problem/1950/D
 */
public class Main {
    /**
     * 将满足要求的数字写出来
     * 然后用递归的思想，用作乘法，最多5层就够用了，因为最小的10 10 10 10 10乘起来已经是100000了
     */
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 100010;
    static int idx = 0;
    static int[] f = new int[N];

    public static void main(String[] args) {
        int T = sc.nextInt();
        for (int i = 1; i < N; i++) {
            int x = i;
            boolean yes = true;
            while (x > 0) {
                if (x % 10 > 1) {
                    yes = false;
                    break;
                }
                x /= 10;
            }
            if (yes) f[++idx] = i;
        }
        while (T-- > 0) {
            int x = sc.nextInt();
            if (check(x)) out.println("YES");
            else out.println("NO");
        }
        out.flush();
    }

    static boolean check(int x) {
        if (x == 1) return true;
        boolean res = false;
        for (int i = 2; i <= idx; i++) {
            if (x % f[i] == 0) {
                res = check(x / f[i]);
                if (res) break;
            }
        }

        return res;
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
